package com.linkhub.oms.admin.common.enums;

import com.google.common.collect.Lists;
import com.linkhub.oms.common.enums.IEnumConvert;
import static com.linkhub.oms.admin.modules.order.constant.DeclareCountryConstant.EU_COUNTRY_LIST;

import com.linkhub.oms.common.enums.logistic.CountryCodeMappingEnum;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.List;

/**
 * @author Jaycle
 * @version 1.0.0
 * @Description DeclareCountryMappingTypeEnum.java
 * @createTime 2024/07/05 22:55
 */
@Getter
@AllArgsConstructor
public enum DeclareCountryMappingTypeEnum  implements IEnumConvert<Integer> {
    // 申报国家：1-美国；2-加拿大；3-日本；4-欧盟；5-其它
    US(1, "美国", Lists.newArrayList(CountryCodeMappingEnum.US)),
    CA(2, "加拿大", Lists.newArrayList(CountryCodeMappingEnum.CA)),
    JP(3, "日本", Lists.newArrayList(CountryCodeMappingEnum.JP)),
    EU(4, "欧盟", EU_COUNTRY_LIST),

    ;
    private final Integer code;
    private final String desc;
    private final List<CountryCodeMappingEnum> countries;

    @Override
    public Integer getCode() {
        return this.code;
    }

    public static Integer getCodeByCode( String countryCode ) {
        for (DeclareCountryMappingTypeEnum declareCountry : DeclareCountryMappingTypeEnum.values()) {
            if (declareCountry.countries.stream().anyMatch(country -> country.getCountryCode().equals(countryCode))) {
                return declareCountry.getCode();
            }
        }
        return 5; // 默认返回值
    }

    public static boolean isEu( String countryCode ) {
            if (DeclareCountryMappingTypeEnum.EU.countries.stream().anyMatch(country -> country.getCountryCode().equals(countryCode))) {
                return true;
            }

        return false; // 默认返回值
    }

    public static void main(String[] args) {
        System.out.println(DeclareCountryMappingTypeEnum.getCodeByCode("CA"));
        System.out.println(DeclareCountryMappingTypeEnum.isEu("AT"));
    }
}